<?php get_instance()->view('common/header');?>
<style>

</style>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php echo $title;?></h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li class="btn-group"> <a class="btn default ml_5 return" href="<?php echo $backUrl;?>"><i class="fa fa-chevron-left"></i> 返回</a> </li>
                        <li> <i class="fa fa-home"></i> <a href="<?php echo $backUrl;?>"> 商品列表  <i class="fa fa-angle-right"></i> </a></li>
                        <li><a href="javascript:void(0);"><?php echo $add ? '添加' : '编辑';?></a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
	            <div class="col-md-12">
	            <div class="tabbable tabbable-custom tabbable-custom-profile">
                        <ul class="nav nav-tabs">
                            <li class="active"><a href="#tab_1_1" data-toggle="tab">基本信息</a></li>
                            <li class=""><a href="#tab_1_2" data-toggle="tab">规格/属性</a></li>
                            <li class=""><a href="#tab_1_3" data-toggle="tab">商品详情</a></li>
                        </ul>
                         <form action="<?php echo getUrl('product/home/save')?>" class="form-horizontal" method="post" id="main-form" novalidate="novalidate">
                             <input type="hidden" value="<?php echo $backUrl;?>" class="form-control" name="back_url"/>
							<div class="tab-content">
								<!--收货地址-->
								<div class="tab-pane active" id="tab_1_1">
									<div class="table-actions-wrapper " style="float: right"></div>
									<div class="table-responsive">
										<div class="table-container">
											<!-- table -->
											<div class="form-body">
                                                <!-- 搜索商家 -->
                                                <div class="form-group">
                                                    <label class="control-label col-md-2">所属商家<span class="required">*</span></label>
                                                    <div class="col-md-6">
                                                        <input class="form-control required" name="merchant_id" type="hidden">
                                                        <?php if (!$changeMerchant):?>
                                                            <input class="form-control required" name="merchant_name" value="<?php echo $merchant['shop_name']?>" readonly>
                                                        <?php endif;?>
                                                    </div>
                                                </div>
                                                <!-- 搜索商家 -->
                                                <div class="form-group">
                                                    <label class="control-label col-md-2">商家分类<span class="required">*</span></label>
                                                    <div class="col-md-6">
                                                        <select class="form-control required" name="category_id">
                                                            <option></option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="control-label col-md-2">商品图标<span class="required">*</span></label>
                                                    <div class="col-md-6">
                                                        <div class="cropitMaster-box" style="width:124px;height:124px;&quot;">
                                                            <img style="width:100%;height:100%;" id="icn-img" alt="" src="<?php echo ! $add ? $info['icon']['og'] : getDefaultImg();?>">
                                                        </div>
                                                        <a class="upload-btn" href="javascript:void(0);">选择上传图片（320*320）</a>
                                                        <input type="hidden" name="icon" id="pic" >
                                                    </div>
                                                </div>
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">商品名称<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required" placeholder="输入商品名称" name="name" type="text" value="<?php echo ! $add ? $info['name'] : '';?>">
			                                        </div>
			                                    </div>
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">副标题</label>
			                                        <div class="col-md-6">
			                                            <input class="form-control" placeholder="输入商品副标题" name="subtitle" type="text" value="<?php echo ! $add ? $info['subtitle'] : '';?>">
			                                        </div>
			                                    </div>
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">商品价格<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required number" placeholder="输入商品价格" name="goods_price" type="text" value="<?php echo ! $add ? $info['goods_price'] : '';?>">
			                                        </div>
			                                    </div>
                                                <div class="form-group">
                                                    <label class="control-label col-md-2">会员专属<span class="required">*</span></label>
                                                    <div class="col-md-6" style="margin-left: 18px;">
                                                        <div class="radio-list">
                                                            <label class="radio-inline"><input name="is_special" <?php if( ! $add && $info['is_special'] == 1):?> checked <?php elseif($add):?> checked <?php endif;?> value="1" type="radio"> 否 </label>
                                                            <label class="radio-inline"><input name="is_special" <?php if( ! $add && $info['is_special'] == 2):?> checked<?php endif;?> value="2" type="radio"> 是 </label>
                                                        </div>
                                                    </div>
                                                </div>
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">打包费<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required number" placeholder="输入打包费" name="lunch_box_fee" type="text" value="<?php echo ! $add ? $info['lunch_box_fee'] : '';?>">
			                                        </div>
			                                    </div>
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">库存设置<span class="required">*</span></label>
			                                        <div class="col-md-6" style="margin-left: 18px;">
			                                            <div class="radio-list">
			                                                <label class="radio-inline"><input name="is_limited" <?php if( ! $add && $info['is_limited'] == 1):?> checked <?php elseif($add):?> checked <?php endif;?> value="1" type="radio"> 有限库存 </label>
			                                                <label class="radio-inline"><input name="is_limited" <?php if( ! $add && $info['is_limited'] == 2):?> checked<?php endif;?> value="2" type="radio"> 无限库存 </label>
			                                            </div>
			                                        </div>
			                                    </div>
			                                    <div class="form-group" id="quantity">
			                                        <label class="control-label col-md-2">库存<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required number" name="quantity" type="text" value="<?php echo ! $add ? $info['quantity'] : '0';?>">
			                                        </div>
			                                    </div>
			                                    <!-- 运费  -->
			                                    <div class="form-group">
			                                        <label class="control-label col-md-2">重量（kg）<span class="required">*</span></label>
			                                        <div class="col-md-6">
			                                            <input class="form-control required number" placeholder="设置商品重量" name="weight" type="text" value="<?php echo ! $add ? $info['weight'] : '0';?>">
			                                        </div>
			                                    </div>
<!--                                                <div class="form-group">-->
<!--                                                    <label class="control-label col-md-2">是否包邮<span class="required">*</span></label>-->
<!--                                                    <div class="col-md-6" style="margin-left: 18px;">-->
<!--                                                        <div class="radio-list">-->
<!--                                                            <label class="radio-inline"><input name="is_free_shipping" --><?php //if( ! $add && $info['is_free_shipping'] == 1):?><!-- checked --><?php //elseif($add):?><!-- checked --><?php //endif;?><!-- value="1" type="radio"> 否 </label>-->
<!--                                                            <label class="radio-inline"><input name="is_free_shipping" --><?php //if( ! $add && $info['is_free_shipping'] == 2):?><!-- checked--><?php //endif;?><!-- value="2" type="radio"> 是 </label>-->
<!--                                                        </div>-->
<!--                                                    </div>-->
<!--                                                </div>-->
			                                    <!-- 轮播图 -->
                                                <div class="form-group">
                                                    <label class="control-label col-md-2">轮播图<span class="required">*</span></label>
                                                    <div class="col-md-6">
                                                        <div id="uploader-demo">
                                                            <!--用来存放item-->
                                                            <div class="uploader-list">
                                                                <?php if (! $add && $info['img']):?>
                                                                    <?php  foreach ($info['img'] as $v):?>
                                                                        <div id="" class="file-item thumbnail pic-list">
                                                                            <img src="<?php echo $v; ?>">
                                                                            <a title="删除" class="delete-btn hide" href="javascript:void(0);" style="color:#b94a48;position:absolute;top:-10px;right:-5px;background-color:#ffff;height:17px;width:15px;font-size:12px;padding:2px;">
                                                                                <i class="fa fa-times"></i>
                                                                            </a>
                                                                            <input name="img[]" type="hidden" class="file-name" value="<?php echo $v; ?>">
                                                                        </div>
                                                                    <?php endforeach; endif;?>
                                                                <div id="filePicker" class="file-item thumbnail webuploader-container">
                                                                    <div class="webuploader-pick">
                                                                        <div style="position:absolute;top:0;left:0;width:100%;height:100%;padding-top:70px;color:grey;">选择图片</div>
                                                                        <img title="选择上传图片" src="<?php echo getDefaultImg(); ?>">
                                                                    </div>
                                                                    <div id="rt_rt_1c2t7atu83351ra0bvm7gcgnu1" style="position: absolute; top: 4px; left: 4px; width: 100px; height: 100px; overflow: hidden; bottom: auto; right: auto;">
                                                                        <input type="file" name="file" class="webuploader-element-invisible" multiple="multiple" accept="image/*">
                                                                        <label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);">
                                                                        </label>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <script type="text/javascript">
                                                                $(function(){
                                                                    uploadImg({
                                                                        box:'#uploader-demo',
                                                                        uploadBtn:"#filePicker",
                                                                        fileName:'img[]',
                                                                        width:110,  //显示缩略图宽带
                                                                        uploadUrl:'<?php echo getUrl('product/home/uploadImgs');?>',
                                                                        height:100,	//显示缩略图高度
                                                                        number:3
                                                                    });

                                                                });

                                                            </script>
                                                        </div>
                                                    </div>
                                                </div>
										        <!-- 状态 -->
										        <div class="form-group">
			                                        <label class="control-label col-md-2">状态<span class="required">*</span></label>
			                                        <div class="col-md-6" style="margin-left: 18px;">
			                                            <div class="radio-list">
			                                                <label class="radio-inline"><input name="status" <?php if( ! $add && $info['status'] == 2):?> checked <?php endif;?> value="2" type="radio"> 上架 </label>
			                                                <label class="radio-inline"><input name="status" <?php if( ! $add && $info['status'] == 1):?> checked<?php endif;?> value="1" type="radio"> 下架 </label>
                                                            <?php if( (! $add && $info['status'] == 0) || $add):?>
			                                                    <label class="radio-inline"><input name="status"  checked value="0" type="radio"> 草稿 </label>
                                                            <?php endif;?>
			                                            </div>
			                                        </div>
			                                    </div>
			                                    <!-- 按钮 -->
			                                    <div class="form-group">
						                            <div class="col-md-offset-2 col-md-9" style="padding-left: 0;">
						                            	<a class="btn blue button-next" href="javascirpt:void(0);" data-toggle="tab" >继续 <i class="m-icon-swapright m-icon-white"></i></a>
						                            </div>
					                            </div>
                                                <script type="text/javascript">
													$(function(){
														$('.button-next').click(function(){
															$('[href="#tab_1_2"]').click();
														});
													});
					                            </script>
			                                </div>
											<!--  -->
										</div>
									</div>
								</div>
								<!--  -->
								<!--商品规格-->
                                <div class="tab-pane" id="tab_1_2">
                                    <div class="table-actions-wrapper " style="float: right"></div>
                                    <div class="table-responsive">
                                        <div class="table-container">
                                            <!-- 开始 -->
                                            <!--规格-->
                                            <div class="form-body">
                                                <?php if($add || empty($property)){?>
                                                    <div class="row option">
                                                        <label class="col-md-2 control-label">规格名称<span class="required">*</span></label>
                                                        <div class="col-md-2">
                                                            <div class="form-group">
                                                                <div class="col-md-12">
                                                                    <input class="form-control required" placeholder="输入规格名称" name="lable[0][lable]" type="text" value="">
                                                                    <span class="help-block">
																		<code>输入商品的规格名称</code>
																	</span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-3">
                                                            <div class="form-group">
                                                                <div class="col-md-12">
                                                                    <input type="hidden" id="select2_sample0" placeholder="输入属性后回车" name="lable[0][value]" class="form-control select2 required" value="">
                                                                    <span class="help-block">
																		<code>输入属性名称</code>
																	</span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                <?php }else{foreach ($property as $k=>$v){?>
                                                    <div class="row option">
                                                        <label class="col-md-2 control-label">规格名称<span class="required">*</span></label>
                                                        <div class="col-md-2">
                                                            <div class="form-group">
                                                                <div class="col-md-12">
                                                                    <input class="form-control required" placeholder="输入规格名称" name="lable[<?php echo $k?>][lable]" type="text" value="<?php echo (! $add) ? $v['lable'] : ''?>">
                                                                    <span class="help-block">
																		<code>输入商品的规格名称</code>
																	</span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-3">
                                                            <div class="form-group">
                                                                <div class="col-md-12">
                                                                    <input type="hidden" id="select2_sample<?php echo $k?>" placeholder="输入属性后回车" name="lable[<?php echo $k?>][value]" class="form-control select2 required" value="<?php echo (! $add) ? implode(',', $v['value']) : ''?>">
                                                                    <span class="help-block">
																		<code>输入属性名称</code>
																	</span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <script type="text/javascript">
                                                        $(function(){
                                                            $("#select2_sample<?php echo $k?>").select2({
                                                                tags: []
                                                            });
                                                        })
                                                    </script>
                                                <?php }}?>
                                            </div>

                                            <!--属性-->
                                            <div class="form-body" id="property_option">
                                                <?php if($add || empty($tags)){?>
                                                    <div class="row option property">
                                                        <label class="col-md-2 control-label">属性名称<span class="required">*</span></label>
                                                        <div class="col-md-2">
                                                            <div class="form-group">
                                                                <div class="col-md-12">
                                                                    <input class="form-control required" placeholder="输入属性名称" name="tag[0][tag]" type="text" value="">
                                                                    <span class="help-block">
																		<code>输入商品的属性名称</code>
																	</span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-3">
                                                            <div class="form-group">
                                                                <div class="col-md-12">
                                                                    <input type="hidden" id="select2_tag0" placeholder="输入属性值后回车" name="tag[0][value]" class="form-control select2 required" value="">
                                                                    <span class="help-block">
																		<code>输入属性值</code>
																	</span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                            <div class="col-md-1">
                                                                <div class="form-group">
                                                                    <div class="col-md-12">
                                                                        <div style="margin-top: 10px;">
                                                                            <a href="javascript:void(0);" class="add-option-btn"><img src="<?php echo $this->staticUrl;?>img/4.png" alt="" style="display: inline-block;margin-top: -3px;"> 添加</a>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                    </div>
                                                <?php }else{foreach ($tags as $k=>$v){?>
                                                    <div class="row option property">
                                                        <label class="col-md-2 control-label">属性名称<span class="required">*</span></label>
                                                        <div class="col-md-2">
                                                            <div class="form-group">
                                                                <div class="col-md-12">
                                                                    <input class="form-control required" placeholder="输入属性名称" name="tag[<?php echo $k?>][tag]" type="text" value="<?php echo (! $add) ? $v['tag_name'] : ''?>">
                                                                    <span class="help-block">
																		<code>输入商品的属性名称</code>
																	</span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-3">
                                                            <div class="form-group">
                                                                <div class="col-md-12">
                                                                    <input type="hidden" id="select2_tag<?php echo $k?>" placeholder="输入属性值后回车" name="tag[<?php echo $k?>][value]" class="form-control select2 required" value="<?php echo (! $add) ? implode(',', $v['tag_value']) : ''?>">
                                                                    <span class="help-block">
																		<code>输入属性值名称</code>
																	</span>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-md-1">
                                                            <div class="form-group">
                                                                <div class="col-md-12">
                                                                    <div style="margin-top: 5px;">
                                                                        <?php if($k){?>
                                                                            <a href="javascript:void(0);" class="remove_option"><img src="<?php echo $this->staticUrl;?>img/2.png" alt=""></a>
                                                                        <?php }else{?>
                                                                            <a href="javascript:void(0);" class="add-option-btn"><img src="<?php echo $this->staticUrl;?>img/4.png" alt="" class="add-btn1"> 添加</a>
                                                                        <?php }?>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <script type="text/javascript">
                                                        $(function(){
                                                            $("#select2_tag<?php echo $k?>").select2({
                                                                tags: []
                                                            });
                                                        })
                                                    </script>
                                                <?php }}?>
                                            </div>
                                            <!-- 按钮 -->
                                            <div class="form-group">
                                                <div class="col-md-offset-2 col-md-9" style="padding-left: 0;">
                                                    <a class="btn blue button-next btn_variant" href="javascirpt:void(0);" data-toggle="tab" >继续 <i class="m-icon-swapright m-icon-white"></i></a>
                                                </div>
                                            </div>
                                            <script type="text/javascript">
                                                $(function(){
                                                    $('.btn_variant').click(function(){
                                                        $('[href="#tab_1_3"]').click();
                                                    });
                                                });
                                            </script>

                                            <!--  -->
                                            <!-- 结束 -->
                                        </div>
                                    </div>
                                </div>
								<!--  -->
								<!--商品详情-->
								<div class="tab-pane" id="tab_1_3">
									<div class="table-actions-wrapper " style="float: right"></div>
									<div class="table-responsive">
										<div class="table-container">
											<div class="form-body">
											<?php if($add){?>
											<!-- 文本 -->
											<div class="form-group option">
												<label class="col-md-2 control-label">文本</label>
												<div class="col-md-4">
													<textarea class="form-control" rows="6" name="detail[1]"></textarea>
												</div>
												<div class="col-lg-1">
			                                           <div style="margin-top: 10px;">
															<a href="javascript:void(0);" class="delete"><img src="<?php echo $this->staticUrl;?>img/2.png" alt=""></a>
														</div>
			                                       </div>
											</div>
											<!-- 文本结束 -->
											<!-- 图片 -->
											<div class="form-group option">
												<label class="col-md-2 control-label">图片</label>
			                                       <div class="col-lg-4">
			                                           <input type="file" class="show-url" name="2_detail" data-show-remove="false" data-show-loader="true" data-default-file=""/>
			                                       </div>
			                                       <div class="col-lg-1">
			                                           <div style="margin-top: 10px;">
															<a href="javascript:void(0);" class="delete"><img src="<?php echo $this->staticUrl;?>img/2.png" alt=""></a>
														</div>
			                                       </div>
												   <script>
				                                       $('.show-url').dropify({
				                                           messages: {'default': '点击上传图片','replace': '点击图片上传替换图片','remove':'删除图片','error':'Ooops, something wrong appended.'}}
				                                       ).on('dropify.beforeClear',function(event, element) {
				
				                                           return confirm("Do you really want to delete \"" + element.filename + "\" ?");
				                                       });
				                                   </script>
											</div>
											<?php }else{?>
												<?php  foreach ($detail as $k=>$v){?>
													<?php if($v['type'] == 1){?>
														<!-- 文本 -->
														<div class="form-group option">
															<label class="col-md-2 control-label">文本</label>
															<div class="col-md-4">
																<textarea class="form-control" rows="6" name="detail[<?php echo $v['sort']?>]"><?php echo $v['content']?></textarea>
															</div>
															<div class="col-lg-1">
						                                           <div style="margin-top: 10px;">
																		<a href="javascript:void(0);" class="delete"><img src="<?php echo $this->staticUrl;?>img/2.png" alt=""></a>
																	</div>
						                                       </div>
														</div>
														<!-- 文本结束 -->
													<?php }elseif($v['type'] == 2){?>
														<!-- 图片 -->
														<div class="form-group option">
															<label class="col-md-2 control-label">图片</label>
						                                       <div class="col-lg-4">
						                                       		<input type="hidden" name="imgs[<?php echo $v['sort']?>]" value="<?php echo $v['imgs'];?>">
						                                           <input type="file" class="show-url" name="<?php echo $v['sort']?>_detail" data-show-remove="false" data-show-loader="true" data-default-file="<?php echo strstr($v['content'],'?',true)?>"/>
						                                       </div>
						                                       <div class="col-lg-1">
						                                           <div style="margin-top: 10px;">
																		<a href="javascript:void(0);" class="delete"><img src="<?php echo $this->staticUrl;?>img/2.png" alt=""></a>
																	</div>
						                                       </div>
															   <script>
							                                       $('.show-url').dropify({
							                                           messages: {'default': '点击上传图片','replace': '点击图片上传替换图片','remove':'删除图片','error':'Ooops, something wrong appended.'}}
							                                       ).on('dropify.beforeClear',function(event, element) {
							
							                                           return confirm("Do you really want to delete \"" + element.filename + "\" ?");
							                                       });
							                                   </script>
														</div>
													<?php }?>
												<?php }?>
											<?php }?>
											<!-- 图片结束 -->
											<div class="form-group" id="add-btn">
												<label class="col-md-2 control-label"></label>
												<div class="col-lg-4">
													<div style="margin-top: 10px;">
														<a href="javascript:void(0);" class="add-text"><img src="<?php echo $this->staticUrl;?>img/4.png" class="add-btn1"> 添加文本</a>
														<a href="javascript:void(0);" class="add-imgs"><img src="<?php echo $this->staticUrl;?>img/4.png" class="add-btn1"> 添加图片</a>
													</div>
												</div>
												
												<script type="text/javascript">
														$(function(){
															var detail_option = <?php echo ($add ? 3 : (isset($detail[count($detail) - 1]['sort']) ? ($detail[count($detail) - 1]['sort'] + 1):1) )?>;


                                                            var deleteImg = "<?php echo $this->staticUrl;?>img/2.png";
															  
															$('.add-text').click(function(){
																//文本
																var text = '<div class="form-group option">'
																	text +='	<label class="col-md-2 control-label">文本</label>'
																	text +='	<div class="col-md-4">'
																	text +='		<textarea class="form-control" rows="6" name="detail['+detail_option+']"></textarea>'
																	text +='	</div>'
																	text +='	<div class="col-lg-1">'
																	text +='		<div style="margin-top: 10px;">'
																	text +='			<a href="javascript:void(0);" class="delete"><img src="'+deleteImg+'" alt=""></a>'
																	text +='		</div>'
																	text +=' 	</div>'
																	text +='</div>'
																		
																$(this).parents('#add-btn').before(text);
																$(this).removeClass('add-text').addClass('add-imgs');
																detail_option++;
															})
															
															$('.add-imgs').click(function(){

																//图片
																var imgs = '<div class="form-group option">'
																	imgs +='	<label class="col-md-2 control-label">图片</label>'
																	imgs +='	<div class="col-lg-4">'
																	imgs +='		<input type="file" class="show-url" name="'+detail_option+'_detail" data-show-remove="false" data-show-loader="true" data-default-file=""/>'
							                                        imgs +='	</div>'
							                                        imgs +='	<div class="col-lg-1">'
							                                        imgs +='		<div style="margin-top: 10px;">'
							                                        imgs +='			<a href="javascript:void(0);" class="delete"><img src="'+deleteImg+'" alt=""></a>'
							                                        imgs +='		</div>'
							                                        imgs +=' 	</div>'
																	imgs +='</div>'
																		
																$(this).parents('#add-btn').before(imgs);
										                           $('.show-url').dropify({
							                                           messages: {'default': '点击上传图片','replace': '点击图片上传替换图片','remove':'删除图片','error':'Ooops, something wrong appended.'}}
							                                       ).on('dropify.beforeClear',function(event, element) {
							
							                                           return confirm("Do you really want to delete \"" + element.filename + "\" ?");
							                                       });
										                           $(this).addClass('add-text').removeClass('add-imgs');
										                           detail_option++;
															})

															$('.delete').live('click',function(){
																$(this).parents('.option').remove();
															})
														})
												</script>
											</div>

												<!-- 结束 -->
											</div>
											<div class="form-group">
					                            <div class="col-md-offset-2 col-md-9" style="padding-left: 0;">
					                           	 	<input name="id" value="<?php echo ! $add ? $info['id'] : '';?>" type="hidden">
					                            	<button class="btn green"><i class="fa fa-save"></i> 保存</button>
					                            	<a class="btn default seach-btn" href="<?php echo getUrl('member/consumer');?>"><i class="fa fa-chevron-left"></i> 返回</a>
					                            </div>
				                            </div>
										</div>
									</div>
								</div>
								<!--  -->
							</div>
							<!--  -->
                            
						</form>
						<!-- form -->
                </div>
	            </div>
            </div>
        </div>
    </div>
</div>
<div class="content-box" type="0" index="0">
    <script index="0" id="" name="free_content[]" type="text/plain"></script>
</div>
<script>
$(function(){
    cropitMaster({
        uploadBtn:$('.upload-btn'),
        height:'322px',
        width:'322px',
        complete:function(btn,data){
            $('#icn-img').attr('src', data);
            $('#pic').val(data).change();
        }
    });

	var option = <?php echo $add ? 1 : count($property) ?>;
        $("#select2_sample0").select2({
            tags: []
        });
        $("#select2_tag0").select2({
            tags: []
        });
        
		$('.add-option-btn').click(function(){
			if($(".property").length >= 5){
				show_message({status:0,message:"最多只能添加5个"});
				return;
			}
            var deleteImg = "<?php echo $this->staticUrl;?>img/2.png";
			var html = '<div class="row option property">';
				html +='<label class="col-md-2 control-label"><span class="required"></span></label>';
				html +='<div class="col-md-2">';
				html +='<div class="form-group">';
				html +='	<div class="col-md-12">';
				html +='		<input class="form-control required" placeholder="输入标签名称" name="tag['+option+'][tag]" type="text">';
				html +='		<span class="help-block">';
				html +='			<code>输入商品的属性名称</code>';
				html +='		</span>';
				html +='	</div>';
				html +='</div>';
				html +='</div>';
				html +='<div class="col-md-3">';
				html +='	<div class="form-group">';
				html +='		<div class="col-md-12">';
				html +='			<input type="hidden" id="select2_sample'+option+'" placeholder="输入属性后回车" name="tag['+option+'][value]" class="form-control select2 required" value="">';
				html +='			<span class="help-block">';
				html +='				<code>输入属性值名称</code>';
				html +='			</span>';
				html +='		</div>';
				html +='	</div>';
				html +='</div>';
				html +='<div class="col-md-1">';
				html +='	<div class="form-group">';
				html +='		<div class="col-md-12">';
				html +='			<div style="margin-top: 5px;">';
				html +='				<a href="javascript:void(0);" class="remove_option"><img src="'+deleteImg+'" alt=""></a>';
				html +='			</div>';
				html +='		</div>';
				html +='	</div>';
				html +='</div>';
				html +='</div>';

				$('#property_option').append(html);
				$("#select2_sample"+option).select2({
		            tags: []
		        });
				option++;
		});

		$('.remove_option').live('click',function(){
			$(this).parents('.option').remove();
		})
		
	})
</script>
<script type="text/javascript">
    $(function(){
        $.e_validate.init('#main-form', {});
		
        $('select[name="category_id"]').select2({placeholder: '先选择商家,再选择分类'});
        <?php if ($changeMerchant):?>
        //select2 搜索商家
        $('input[name="merchant_id"]').select2({
            closeOnSelect: true,
            placeholder: '搜索商家,输入店铺名称、电话',
            minimumInputLength: 2,
            ajax: {
                url: "<?php echo getUrl('common/searchUserName')?>",
                dataType: 'json',
                data: function (term, page) {
                    return {
                    	keyword: term
                    };
                },
                results: function (data, page) {
                    return {
                        results: data
                    };
                }
            },
            formatResult: function(movie) {
            	return movie.name;
            },
            formatSelection: function(movie) {
                return movie.name;
            }, 
            dropdownCssClass: "bigdrop",
            escapeMarkup: function (m) {
                return m;
            }
        }).change(function (evt) {
            //根据所选商家 获取分类
            $.get('<?php echo getUrl('common/getCustomList')?>',{merchant_id:(evt.added.id)},function(data){
            	data = eval('('+data+')')
// 	            console.log(data)
				$('select[name="category_id"]').select2("val",""); //设置值为空
            	$('select[name="category_id"]').html('');//清除选项
		        $('select[name="category_id"]').append('<option></option>');//加入默认选项
	            $.each(data,function(index,element){
		            $('select[name="category_id"]').append('<option value="'+element.id+'">'+element.cat_name+'</option>');
		        })
	            
            })
        });
        <?php endif;?>
        <?php if(! $add || !$changeMerchant) {?>
        	//商家设置默认值
	        $('input[name="merchant_id"]').val(<?php echo $info['merchant_id']?>);//设置商家
	        $('input[name="merchant_id"]').parents('.col-md-6')
	        .find('.select2-chosen')
	        .text('<?php echo $merchant['shop_name']?>')
	        .parent('a')
	        .removeClass('select2-default');

        	//所属分类 
        	var selections = <?php echo json_encode($category)?>;

	        $.each(selections,function(index,element){
		    	$('select[name="category_id"]').append('<option value="'+element.id+'">'+element.cat_name+'</option>');
		    })
        	$('select[name="category_id"]').select2('val', [<?php echo $info['category_id']?>]);

        	//库存设置
        	if(<?php echo $info['is_limited']?> == 2){
        		$('#quantity').hide();
        	}
        <?php }?>
        
        $('input[name="is_limited"]').click(function(){
			var val = $(this).val()
			if (val == 1){
				$('#quantity').show();
			}else{
				$('#quantity').hide();
			}
        })
    });
</script>

</body>
</html>